const crypto = require('crypto');
const { authToken } = require('../config/config')

module.exports = (ctx) => {
  let { echostr, signature, timestamp, nonce } = ctx.query;
  //token、timestamp、nonce
  let params = [authToken, timestamp, nonce];
  let tmp = params.sort().join('');
  let mySign = crypto.createHash('sha1').update(tmp).digest('hex');

  if (mySign === signature) {
    ctx.body = echostr;
  } else {
    ctx.body = '非法请求'
  }

}